/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package jollylengkono.skripsi.Groups.action;

import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import jollylengkono.skripsi.Groups.form.GroupsUpdateForm;
import jollylengkono.skripsi.dao.GroupsDao;
import jollylengkono.skripsi.dao.ObjectsDao;
import jollylengkono.skripsi.model.Groups;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

/**
 *
 * @author Nicholai
 */
public class GroupsUpdate extends Action {
    private String FORWARD;
    private int STATE;

    public GroupsUpdate() {
    }
    
    @Override
    public ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response) throws Exception {
        GroupsUpdateForm groupsForm = (GroupsUpdateForm) form;
        Groups group = new Groups();
        group.setCreated(groupsForm.getCreated());
        group.setDescription(groupsForm.getDescription());
        group.setGroupName(groupsForm.getGroupName());
        group.setId(groupsForm.getId());
        List objects = new ArrayList();
        for(String idObject : groupsForm.getListIdObject()) {
            objects.add(new ObjectsDao().read(Long.parseLong(idObject)));
        }
        group.setListObject(objects);
        this.STATE = new GroupsDao().update(group);
        if (this.STATE==1) {
            this.FORWARD="success";
        } else {
            this.FORWARD="fail";
        }
        return mapping.findForward(FORWARD);
    }
}
